<?php
/**
 * 类说明 :
 * User: 刘明昆
 * Date: 2019/1/24
 * Time: 13:56
 */
header("Content-type: text/html; charset=utf-8");
require 'dbUtils.php';
require 'jsonMsg.php';

    //获取用户名和密码
    $username=$_POST['username'];
    $pwd=$_POST['pwd'];
    //获取数据库实例
    $link=mysqlDB::getInstance();
    //查询用户名或密码是否正确
    $sql="select * from admin_user where username='$username' and pwd='$pwd';";
    //执行sql
    $result=$link->query($sql);
    $arr=array();
    if(mysqli_num_rows($result)<1){
        return json(200,"用户名或密码错误",$arr);
    }else{
        while($row=mysqli_fetch_assoc($result)){
            $arr[]=$row;
        }
        return json(200,"登录成功",$arr);
    }

    //实例化对象
//    $admin =new AdminUser();
//
//    //判断是否有记录
//    if($result->num_rows >0){
//
//        $rows=$result->fetch_assoc();
//        $admin->setId($rows['id']);
//        $admin->setUsername($rows['username']);
//        $admin->setPwd($rows['pwd']);
//        //$json_arr = array("id"=>$rows['id'],"username"=>$rows['username'],"pwd"=>$rows['pwd']);
//    }else{
//        $admin=null;
//    }

//$json_obj = json_encode($json_arr);
//echo $json_obj;
    //echo json_encode(object_to_array($admin));
//echo object_to_json($admin);
//    return $admin;
